<template>
  <view class="app">
    <web-view src="https://www.drk88.com/static-content.html" frameborder="0" width="100%" height="600px" id="phpIframe"></web-view>
    <iframe src="https://www.drk88.com/static-content.html" frameborder="0" width="100%" height="600px" id="phpIframe"></iframe>

    <view class="btn-group">
			<navigator :url="`/pages/indent/list?state=1`" open-type="redirect" class="mix-btn">查看订单</navigator>
			<navigator url="/pages/index/index" open-type="switchTab" class="mix-btn hollow">返回首页</navigator>
		</view>
  </view>
</template>

<script>
import GoodIndent from '../../api/goodIndent'
import Pay from '../../api/pay'
import User from '../../api/user'
import { micromessenger } from 'utils'
import { authMsg } from '../../utils'
import { mapMutations } from 'vuex'
export default {
  data() {
    return {
      confirmDisabled: false,
      id: '',
      payType: 'xyk',
      orderInfo: {
        total: 0,
        user: {
          money: 0,
        },
      },
      index: 0,
      jweixin: null,
      modalName: null,
      jweixin: null,
      user: {},
      paySuccess: `/pages/money/paySuccess`,
      form: {
        account: '',
        terminal: '',
        order_number: '',
        order_currency: '',
        order_amount: 0,
        methods: 'KOR_Credit Card',
        billing_lastName: '',
        billing_firstName: '',
        billing_email: '',
        billing_phone: '',
        key: '/',
      },
    }
  },
  computed: {},
  onLoad(options) {
    if (!options.id) {
      this.$api.msg(this.$t('common.arguments'))
      return false
    }
    this.id = options.id
    // #ifdef H5
    if (micromessenger()) {
      this.getWeixin()
    }
    // #endif
  },
  onShow() {
    uni.setNavigationBarTitle({
      title: this.$t('money.pay.title'),
    })
    // this.loginCheck()
    // this.getList()
    // this.getUser()
  },
  methods: {
    ...mapMutations(['loginCheck']),
    getUser() {
      const that = this
      User.detail(function (res) {
        that.user = res
      })
    },
    getList() {
      const that = this
      GoodIndent.pay(this.id, function (res) {
        that.orderInfo = res
        if (res.state !== 1 && res.state !== 4) {
          uni.redirectTo({
            url: that.paySuccess,
          })
        }
      })
    },
    //选择支付方式
    changePayType(type) {
      this.payType = type
    },
    showModal(e) {
      this.modalName = e
    },
    hideModal(e) {
      this.modalName = null
    },
    goBack() {
      this.hideModal()
      this.getList()
    },
    getWeixin() {
      this.jweixin = require('jweixin-module')
      const that = this
      JsSdk.buildConfig(function (res) {
        that.jweixin.config(res)
        that.jweixin.error(function (res) {
          console.log('失败')
        })
      })
    },
    //确认支付
    confirm: async function () {
      const that = this
      this.confirmDisabled = true
      if (this.payType === 1) {
        // 线下转账
        Pay.payOffline(
          {
            id: this.id,
          },
          function (res) {
            // authMsg(['4iOC-HyjJeKK5HiYORcOtrKHvu2Ho1ScVF0aqP3KkzQ'])
            // if(!that.user.email && !that.user.wechat){
            // 	uni.showModal({
            // 	  title: that.$t('common.hint'),
            // 	  content: that.$t('payment_log.notification_enabled'),
            // 	  success (res) {
            // 		if (res.confirm) {
            // 		  uni.redirectTo({
            // 			url: '/pages/set/message'
            // 		  })
            // 		} else if (res.cancel) {
            // 		  uni.redirectTo({
            // 			url: that.paySuccess
            // 		  })
            // 		}
            // 	  }
            // 	})
            // }else{
            uni.redirectTo({
              url: that.paySuccess,
            })
            // }
          }
        )
        that.confirmDisabled = false
      } else {
        // #ifdef H5
        if (micromessenger()) {
          Pay.unifiedPayment(
            {
              platform: this.payType,
              type: 'goodsIndent',
              trade_type: 'JSAPI',
              id: this.id,
            },
            function (res) {
              that.jweixin.chooseWXPay({
                appId: res.msg.appId,
                timestamp: res.msg.timestamp,
                nonceStr: res.msg.nonceStr,
                package: res.msg.package,
                signType: res.msg.signType,
                paySign: res.msg.paySign,
                success: function (res) {
                  uni.redirectTo({
                    url: that.paySuccess,
                  })
                },
                fail(res) {
                  that.$api.msg(that.$t('payment_log.payment_failure'))
                  that.confirmDisabled = false
                },
              })
            },
            function (error) {
              that.$api.msg(error.message)
              that.confirmDisabled = false
            }
          )
        } else {
          // Pay.unifiedPayment({
          // 	platform: this.payType,
          // 	type: 'goodsIndent',
          // 	trade_type: 'MWEB',
          // 	id: this.id,
          // },function(res){
          // 	that.confirmDisabled = false
          // 	that.showModal('payHint')
          // 	window.location.href = res.mweb_url
          // },function(error){
          // 	that.$api.msg(error.message)
          // 	that.confirmDisabled = false
          // })
          Pay.unifiedPayment(
            {
              // email:this.user.email:"jbeier@qq.com"
              id: this.id,
              platform: 'ocean',
              trade_type: 'KOR_Credit Card',
              type: 'goodsIndent',
              order_detail: ``,
            },
            function (response) {
              that.form = { ...that.form, ...response.postdata, billing_address: that.orderInfo.good_location.location + '/' + that.orderInfo.good_location.house }
              localStorage.setItem('formData', JSON.stringify(that.form))
              // that.showModal('payHint')
             
          // window.location.href = 'https://www.drk88.com/static-content.html'

            },
            function (error) {
              that.$api.msg(error.message)
              this.confirmDisabled = false
            }
          )
        }
        // #endif
        // // #ifdef MP
        // Pay.unifiedPayment({
        // 	id: this.id,
        // 	platform: this.payType,
        // 	trade_type: 'JSAPI',
        // 	type: 'goodsIndent'
        // },function(res){
        // 	uni.requestPayment({
        // 		timeStamp: res.msg.timestamp,
        // 		nonceStr: res.msg.nonceStr,
        // 		package: res.msg.package,
        // 		signType: res.msg.signType,
        // 		paySign: res.msg.paySign,
        // 		success(res) {
        // 		  // console.log(res)
        // 		  // 订阅消息
        // 		  authMsg(['4iOC-HyjJeKK5HiYORcOtrKHvu2Ho1ScVF0aqP3KkzQ'])
        // 		  if(!that.user.email && !that.user.wechat){
        // 		  	uni.showModal({
        // 		  	  title: that.$t('common.hint'),
        // 		  	  content: that.$t('payment_log.notification_enabled'),
        // 		  	  success (res) {
        // 		  	    if (res.confirm) {
        // 		  	      uni.redirectTo({
        // 		  	      	url: '/pages/set/message'
        // 		  	      })
        // 		  	    } else if (res.cancel) {
        // 		  	      uni.redirectTo({
        // 		  	      	url: that.paySuccess
        // 		  	      })
        // 		  	    }
        // 		  	  }
        // 		  	})
        // 		  }else{
        // 		  	uni.redirectTo({
        // 		  		url: that.paySuccess
        // 		  	})
        // 		  }
        // 		},
        // 		fail(res) {
        // 			that.$api.msg(that.$t('payment_log.payment_failure'))
        // 			that.getList()
        // 		}
        // 	})

        // },function(error){
        // 	that.$api.msg(error.message)
        // 	that.confirmDisabled = false
        // })
        // // #endif
      }
    },
  },
}
</script>

<style lang="scss">
.app {
  width: 100%;
}

.price-box {
  background-color: #fff;
  height: 265upx;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 28upx;
  color: #909399;

  .price {
    font-size: 50upx;
    color: #303133;
    margin-top: 12upx;
    &:before {
      font-size: 40upx;
    }
  }
}

.pay-type-list {
  margin-top: 20upx;
  background-color: #fff;
  padding-left: 60upx;

  .type-item {
    height: 120upx;
    padding: 20upx 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 60upx;
    font-size: 30upx;
    position: relative;
  }

  .icon {
    width: 100upx;
    font-size: 52upx;
  }
  .icon-erjiye-yucunkuan {
    color: #fe8e2e;
  }
  .icon-weixinzhifu {
    color: #36cb59;
  }
  .icon-alipay {
    color: #01aaef;
  }
  .tit {
    font-size: $font-lg;
    color: $font-color-dark;
    margin-bottom: 4upx;
  }
  .con {
    flex: 1;
    display: flex;
    flex-direction: column;
    font-size: $font-sm;
    color: $font-color-light;
  }
}
.mix-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 630upx;
  height: 80upx;
  margin: 80upx auto 30upx;
  font-size: $font-lg;
  color: #fff;
  background-color: $base-color;
  border-radius: 10upx;
  box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
}
</style>
